package com.gpzx.zx.module.home.frame.view

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.gpzx.zx.R
import com.gpzx.zx.module.home.frame.model.QKLNewsInfo
import com.gpzx.zx.module.home.ui.activity.InfoWebViewActivity
import com.gpzx.zx.module.home.ui.adapter.News24Adapter
import com.gpzx.zx.module.home.ui.fragment.News24Fragment
import com.wkq.base.frame.mosby.delegate.MvpView
import com.wkq.lib_base.adapter.KtDataBindingAdapter

/**
 * 作者: 吴奎庆
 *
 * 时间: 2020/7/16
 *
 * 简介:
 */
class News24View : MvpView {
    var mFragment: News24Fragment
    var mAdapter: News24Adapter? = null

    constructor(fragment: News24Fragment) {
        mFragment = fragment
    }

    fun initView() {
        mFragment.binding.rvContent.layoutManager = LinearLayoutManager(mFragment.activity)
        mAdapter = News24Adapter(mFragment.activity as Context, R.layout.item_news_24)
        mFragment.binding.rvContent.adapter = mAdapter
        mAdapter?.setOnViewClickListener(object : KtDataBindingAdapter.OnAdapterViewClickListener<QKLNewsInfo> {
            override fun onViewClick(v: View?, program: QKLNewsInfo?) {
                InfoWebViewActivity().newInstance(mFragment.activity as Context, "qkl_news", program?.id, program?.news_title)
            }
        })
    }

    fun showData(list: List<QKLNewsInfo>) {
        mAdapter?.addItems(list.toMutableList())
    }
}